// pages/my/update/update.js

const app = getApp()
const log=require("../../../utils/log")
const my = require("../../../utils/MyUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oldpsw: null,
    newpsw: null,
    newpsw2: null,
    show1: false,
    show: false,
    show2: false
  },
  show(e) {
    var flag = e.target.dataset.id
    var show = this.data.show
    var show1 = this.data.show1
    var show2 = this.data.show2
    flag == "old" ? show = !show : (flag == "new" ? show1 = !show1 : show2 = !show2)

    this.setData({
      show,
      show1,
      show2
    })
  },
  hide(e) {
    var flag = e.target.dataset.id
    var show = this.data.show
    var show1 = this.data.show1
    var show2 = this.data.show2
    flag == "old" ? show = !show : (flag == "new" ? show1 = !show1 : show2 = !show2)

    this.setData({
      show,
      show1,
      show2
    })
  },
  oldInput: function (e) {
    this.setData({
      oldpsw: e.detail.value
    })
  },
  newInput: function (e) {
    this.setData({
      newpsw: e.detail.value
    })
  },
  new1Input: function (e) {
    this.setData({
      newpsw2: e.detail.value
    })
  },
  loginBtnClick: function () {
    const _TOKEN = wx.getStorageSync('_TOKEN')
    var that = this.data;
    if (this.data.newpsw == this.data.newpsw2) {
      my.request('/oa-applet/renew-password', 'post', {
        new_pwd: that.newpsw2
      }, {
        pwd: that.oldpsw,
        token: _TOKEN,
        'content-type': 'application/x-www-form-urlencoded'
      }, function (res) {
        wx.hideLoading()
        if (res.data.code == 0) {
          log.info(my.info(new Date(),wx.getStorageSync('userInfo').user_name,"修改了密码"))
          wx.showToast({
            title: res.data.data,
            icon: "none"
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: "none"
          })
        }
      })
    } else {
      wx.showModal({
        cancelColor: 'cancelColor',
        content: '新密码不一致'
      })
    }
  }
})